// ui_lvgl.c
#include "ui_abstract.h"
#include "core_logic.h"
#include "lvgl.h"

static UIEventCallback event_callback = NULL;
static lv_obj_t* status_label = NULL;

// LVGL事件处理
static void btn_event_handler(lv_event_t * e) {
    if (event_callback) {
        event_callback("button_click", "main_button");
    }
}

static void lvgl_update_state(const char* key, const char* value) {
    if (strcmp(key, "app_state") == 0 && status_label) {
        lv_label_set_text(status_label, value);
    }
}

void ui_init(UIEventCallback event_cb) {
    event_callback = event_cb;
    
    // 初始化LVGL
    lv_init();
    // ... 显示初始化代码
    
    // 初始化核心逻辑
    core_init(lvgl_update_state);
    
    // 创建UI元素
    lv_obj_t* btn = lv_btn_create(lv_scr_act());
    lv_obj_set_pos(btn, 10, 10);
    lv_obj_set_size(btn, 120, 50);
    lv_obj_add_event_cb(btn, btn_event_handler, LV_EVENT_CLICKED, NULL);
    
    lv_obj_t* label = lv_label_create(btn);
    lv_label_set_text(label, "Click Me");
    
    status_label = lv_label_create(lv_scr_act());
    lv_obj_set_pos(status_label, 10, 70);
}

void ui_run() {
    while (1) {
        lv_timer_handler();
        // ... 系统延时
    }
}